from rest_framework.pagination import PageNumberPagination
from rest_framework.response import Response


class CustomPagination(PageNumberPagination):
    page_size = 10  # 默认每页显示 10 项
    page_size_query_param = 'pageSize'  # 允许客户端通过 'pageSize' 参数来指定每页显示的数量
    max_page_size = 100  # 最大页数限制，客户端不能通过 'page_size' 请求超过 100 项

    def get_paginated_response(self, data):
        return Response({
            "code": 0,
            "data": {
                "count": self.page.paginator.count,
                "next": self.get_next_link(),
                "previous": self.get_previous_link(),
                "results": data
            },
            "message": ""
        })